package com.fastjars.business.shiro.token;

import com.fastjars.business.shiro.realms.*;
import org.apache.shiro.authc.UsernamePasswordToken;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * BaseToken
 *
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2017/12/23
 * @version 1.0.0
 */
public class BaseToken extends UsernamePasswordToken implements Serializable {
    private static final long serialVersionUID = 6056396987890248227L;

    public static final byte TOKEN_LOGIN_BY_MOBILE = 1;
    public static final byte TOKEN_LOGIN_BY_USERNAME = 2;
    public static final byte TOKEN_LOGIN_BY_EMAIL = 3;
    public static final byte TOKEN_LOGIN_BY_WECHAT = 4;
    public static final byte TOKEN_LOGIN_BY_MOBILE_CODE = 5;

    public static final Map<Byte,Class<? extends AbstractRealm>> TOKEN_TYPE = new HashMap<>();

    static {
        TOKEN_TYPE.put(TOKEN_LOGIN_BY_MOBILE,MobileRealm.class);
        TOKEN_TYPE.put(TOKEN_LOGIN_BY_USERNAME,UsernameRealm.class);
        TOKEN_TYPE.put(TOKEN_LOGIN_BY_EMAIL,EmailRealm.class);
        TOKEN_TYPE.put(TOKEN_LOGIN_BY_WECHAT,WechatRealm.class);
        TOKEN_TYPE.put(TOKEN_LOGIN_BY_MOBILE_CODE,MobileSmsCodeRealm.class);
    }
    /**
     * realm类型
     */
    private byte realmType;
    /**
     * 验证吗
     */
    private String captcha;
    /**
     * 短信验证码
     */
    private Long smsCode;

    public BaseToken(String account,String password){
        super(account,password);
    }

    public BaseToken(byte realmType,String account,String password){
        super(account,password);
        this.realmType = realmType;
    }

    public BaseToken(byte realmType,String account,String password,boolean rememberMe){
        super(account,password,rememberMe);
        this.realmType = realmType;
    }

    public BaseToken(byte realmType,String account,String password,String captcha){
        super(account,password);
        this.realmType = realmType;
        this.captcha = captcha;
    }

    public BaseToken(byte realmType,String account,String password,String captcha,boolean rememberMe){
        super(account,password,rememberMe);
        this.realmType = realmType;
        this.captcha = captcha;
    }

    public BaseToken(byte realmType,String account,String password,Long smsCode){
        super(account,password);
        this.realmType = realmType;
        this.smsCode = smsCode;
    }

    public BaseToken(byte realmType,String account,String password,Long smsCode,boolean rememberMe){
        super(account,password,rememberMe);
        this.realmType = realmType;
        this.smsCode = smsCode;
    }

    public byte getRealmType() {
        return realmType;
    }

    public void setRealmType(byte realmType) {
        this.realmType = realmType;
    }

    public String getCaptcha() {
        return captcha;
    }

    public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }

    public Long getSmsCode() {
        return smsCode;
    }

    public void setSmsCode(Long smsCode) {
        this.smsCode = smsCode;
    }
}
